<template>
  <div>
    <el-radio-group v-if="!item.multiple" @change="handleChange" v-model="changeValue">
      <div v-for="option in getOptions()" :key="option.value" class="img-radio-item">
        <vote
          :value="option.value"
          :type="'img'"
          :vote-list="voteList"
          :total-vote="totalVote"
          v-if="item.config.showVoteResult"
        ></vote>
        <el-image :preview-src-list="[option.image]" :src="option.image" class="image" fit="scale-down">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline" />
          </div>
        </el-image>
        <div class="checkbox-slot">
          <el-radio :label="option.value">
            <div>
              {{ option.label }}
            </div>
          </el-radio>
        </div>
      </div>
    </el-radio-group>
    <el-checkbox-group v-else @change="handleChange" v-model="changeValue">
      <div v-for="option in getOptions()" :key="option.value" class="img-radio-item">
        <vote
          :value="option.value"
          :type="'img'"
          :vote-list="voteList"
          :total-vote="totalVote"
          v-if="item.config.showVoteResult"
        ></vote>
        <el-image :preview-src-list="[option.image]" :src="option.image" class="image" fit="cover">
          <div slot="error" class="image-slot">
            <i class="el-icon-picture-outline" />
          </div>
        </el-image>
        <div class="checkbox-slot">
          <el-checkbox :label="option.value">
            <div>
              {{ option.label }}
            </div>
          </el-checkbox>
        </div>
      </div>
    </el-checkbox-group>
  </div>
</template>

<script>
import mixin from '../mixin'
import voteMixin from '../TVote/VoteMixin'
import vote from '../TVote/vote'

export default {
  name: 'TImageSelect',
  components: { vote },
  mixins: [mixin, voteMixin],
  data() {
    return {
      selectValue: this.value
    }
  },
  methods: {
    handleChange(val) {
      if (Array.isArray(val)) {
        this.handleArrayVote(this.value)
      } else {
        this.handleVote(this.value)
      }
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep .el-radio-button__inner,
.el-radio-group,
.el-checkbox-group {
  display: flex !important;
  flex-wrap: wrap;
}

.img-radio-item {
  border-radius: 10px;
  display: flex;
  flex-direction: column !important;
  align-content: center !important;
  //align-items: center !important;
  border: 1px solid rgba(0, 0, 0, 0.1) !important;
  margin: 3px !important;
  background-color: #fff;

  .image {
    width: 120px;
    height: 120px;
    margin: 5px;
  }
}

.checkbox-slot {
  width: 120px;
  margin: 0 5px;

  ::v-deep .el-checkbox,
  ::v-deep .el-radio {
    width: 120px;
    display: flex;
    // align-items: center;
    white-space: break-spaces;
    word-break: break-all;
    padding: 10px 0;

    .el-checkbox__input,
    .el-radio__input {
      width: 20px;
    }

    .el-checkbox__label,
    .el-radio__label {
      flex: 1;
      overflow: hidden;
      padding-right: 10px;
    }
  }
}

::v-deep .image-slot {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  //background: #f5f7fa;
  color: #909399;
  font-size: 30px;
}

@media (max-width: 750px) {
  .img-radio-item {
    width: calc(50% - 6px);

    .image {
      width: 100%;
      height: 150px;
      margin: 0;
      padding: 5px;
    }
  }
  .checkbox-slot {
    width: 100%;

    .el-checkbox,
    .el-radio {
      width: 100%;
    }
  }
}
</style>
